import * as ACTIONS from '../../actions/examination-analysis/sourceDistributionAction';
import { ENUM_VIEW } from '../../../schema/constants';

/**
 * 数据视图默认状态
 * @type {Object}
 */
export const DEFAULT_DATA_STATE = {
	message: '',
	// 分布数据
	distributionData: {
		isFetching: false,
		data: {}
	},
};


export function sourceDistributionReducer(state = DEFAULT_DATA_STATE, action = {}) {
	let { type, payload } = action;

	switch(type) {
		case ACTIONS.GET_DATA_REQUEST: 
		{
			return Object.assign({}, state, {
				distributionData: {
					isFetching: true,
					data: {}
				}
			});
		}
		case ACTIONS.GET_DATA_SUCCESS: 
		{
			let { data } = payload;
			return Object.assign({}, state, {
				distributionData: {
					isFetching: false,
					data
				}
			})
		}
		case ACTIONS.GET_DATA_FAILURE:
		{
			let { message } = payload;
			return Object.assign({}, state, {
				message,
				distributionData: {
					isFetching: false,
					data: {}
				}
			})
		}
		default: 
			return state;
	}
};